package cn.exrick.xboot.modules.assessment.serviceimpl;

import cn.exrick.xboot.common.utils.DateUtil;
import cn.exrick.xboot.modules.ReportExcel.OutPutAssessmentVo;
import cn.exrick.xboot.modules.assessment.dao.mapper.HkAssessmentScoreMapper;
import cn.exrick.xboot.modules.assessment.entity.HkAssessmentScore;
import cn.exrick.xboot.modules.assessment.service.IHkAssessmentScoreService;
import cn.exrick.xboot.modules.assessment.vo.*;
import cn.exrick.xboot.modules.content.dao.HontUserDao;
import cn.exrick.xboot.modules.content.entity.HontUser;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.trace.http.HttpTrace;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 权限接口实现
 * @author Exrick
 */
@Slf4j
@Service
@Transactional
public class IHkAssessmentScoreServiceImpl extends ServiceImpl<HkAssessmentScoreMapper, HkAssessmentScore> implements IHkAssessmentScoreService {

    @Autowired
    private HkAssessmentScoreMapper hkAssessmentScoreMapper;

    @Autowired
    private HontUserDao hontUserDao;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<Map<String, Object>> selectScoreByHontUserOnDepartement(String departmentId,String beginDate, String endDate) {

        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<Map<String, Object>> maps = hkAssessmentScoreMapper.selectScoreByHontUserOnDepartementId(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId);

        return maps;
    }

    @Override
    public List<Map<String, Object>> selectPlusByHontUserOnDepartementId(String beginDate, String endDate, String departmentId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<Map<String, Object>> maps = hkAssessmentScoreMapper.selectPlusByHontUserOnDepartementId(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId);
        return maps;
    }

    @Override
    public List<Map<String, Object>> selectMinusByHontUserOnDepartementId(String beginDate, String endDate, String departmentId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<Map<String, Object>> maps = hkAssessmentScoreMapper.selectMinusByHontUserOnDepartementId(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId);
        return maps;
    }
    @Override
    public int selectCountByHontUserOnDepartementId(String beginDate, String endDate, String departmentId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        int maps = hkAssessmentScoreMapper.selectCountByHontUserOnDepartementId(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId);
        return maps;
    }
    @Override
    public List<Map<String, Object>> selectByHontUserOnDepartementId(String beginDate, String endDate, String departmentId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<Map<String, Object>> maps = hkAssessmentScoreMapper.selectByHontUserOnDepartementId(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId);
        return maps;
    }

    @Override
    public List<Map<String, Object>> selectCountsByHontUser(String id) {
        return hkAssessmentScoreMapper.selectCountsByHontUser(id);
    }

    @Override
    public List<HkAssessmentScoreGroupByUser> selectHkAssessmentScoreGroupByUser(String beginDate, String endDate, String departmentId,String flowTemplateId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<HkAssessmentScoreGroupByUser> hkAssessmentScoreGroupByUsers = hkAssessmentScoreMapper.selectHkAssessmentScoreGroupByUser(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId,flowTemplateId);
        return hkAssessmentScoreGroupByUsers;
    }

    @Override
    public List<HkAssessmentScoreGroupByUser> selectHkAssessmentScoreGroupByUserAndflowTemplateId(OutPutAssessmentVo outPutAssessmentVo) {
        List<String> dateArray = DateUtil.getDateArray("", outPutAssessmentVo.getBeginDate(), outPutAssessmentVo.getEndDate());
        outPutAssessmentVo.setBeginDate(dateArray.get(0));
        outPutAssessmentVo.setEndDate(dateArray.get(dateArray.size() - 1));
        List<HkAssessmentScoreGroupByUser> hkAssessmentScoreGroupByUsers = hkAssessmentScoreMapper.selectHkAssessmentScoreGroupByUserAndflowTemplateId(outPutAssessmentVo);
        return hkAssessmentScoreGroupByUsers;
    }

    @Override
    public List<HkAssessmentDetailVo> selectHkAssessmentDetailVo(String beginDate, String endDate, String departmentId,String flowTemplateId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<HkAssessmentDetailVo> hkAssessmentDetailVos = hkAssessmentScoreMapper.selectHkAssessmentDetailVo(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId,flowTemplateId);
        return hkAssessmentDetailVos;
    }

    @Override
    public List<SubmitUserVo> getSubmitUserDetail(List<String> processInstanceIds) {
        return hkAssessmentScoreMapper.getSubmitUserDetail(processInstanceIds);
    }

    @Override
    public List<ApproverDetailVo> getApproverDetail(String processInstanceId) {
        return hkAssessmentScoreMapper.getApproverDetail(processInstanceId);
    }

    @Override
    public List<HkAssessmentScoreCountDataVo> getHkAssessmentScoreCountData(String beginDate, String endDate, String departmentId, String flowTemplateId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<HkAssessmentScoreCountDataVo> hkAssessmentScoreCountData = hkAssessmentScoreMapper.getHkAssessmentScoreCountData(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId, flowTemplateId);
        return hkAssessmentScoreCountData;
    }

    @Override
    public List<HkAssessmentScorePlusOrMinusVo> getHkAssessmentScorePlus(String beginDate, String endDate, String departmentId, String flowTemplateId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<HkAssessmentScorePlusOrMinusVo> hkAssessmentScorePlus = hkAssessmentScoreMapper.getHkAssessmentScorePlus(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId, flowTemplateId);
        return hkAssessmentScorePlus;
    }

    @Override
    public List<HkAssessmentScorePlusOrMinusVo> getHkAssessmentScoreMinus(String beginDate, String endDate, String departmentId, String flowTemplateId) {
        List<String> dateArray = DateUtil.getDateArray("", beginDate, endDate);
        List<HkAssessmentScorePlusOrMinusVo> hkAssessmentScoreMinus = hkAssessmentScoreMapper.getHkAssessmentScoreMinus(dateArray.get(0),
                dateArray.get(dateArray.size() - 1), departmentId, flowTemplateId);
        return hkAssessmentScoreMinus;
    }
}